home *** CD-ROM | disk | FTP | other *** search
/ Ray Dream Studio 5 / Ray Dream.iso / pc / DreamSDK / Windows / SAMPLES / CAMERA / CAMS / CAMSDLL.CPP next >
Encoding:
C/C++ Source or Header  |  1997-07-11  |  2.9 KB  |  103 lines

  1. /* $Id: CamSDll.cpp 1.2 1996/07/23 17:33:53 Damien Exp $ */ 
  2.  
  3. // Copyright (c) 1995, Ray Dream, Inc. All rights reserved.
  4.  
  5. ////////////////////////////////////////////////////////////////////////
  6. //   First Camera Example : Spherical Camera                          //
  7. //--------------------------------------------------------------------//
  8. //   DLL Management                                                                                                      //
  9. ////////////////////////////////////////////////////////////////////////   
  10.  
  11.  
  12. #ifndef __CAMSDLL__
  13. #include "CAMSdll.h"
  14. #endif
  15.  
  16. #ifndef __CAMSFAC__
  17. #include "CAMSFac.h"
  18. #endif
  19.  
  20. #ifndef __COMCAMS__
  21. #include "COMCAMS.h"
  22. #endif
  23.  
  24. #ifndef __3DCOFAIL__
  25. #include "3DCoFail.h"
  26. #endif
  27.  
  28. STDAPI DllInitRDCom(IShUtilities* shellUtilities) {
  29.     InitCoFailure(shellUtilities);
  30.     return S_OK;
  31.     }
  32.  
  33. //------------------------------------------------------------------------
  34. /*
  35.  * DllGetClassObject
  36.  *
  37.  * This function gives a IClassFactory with the appropriate CLSID.
  38.  * This DLL must be in the registration database as a InProcServer
  39.  * for the correct CLSID
  40.  *
  41.  * Parameters:
  42.  *  clsID           REFCLSID that identifies the class factory
  43.  *                  desired.  Since this parameter is passed this
  44.  *                  DLL can handle any number of objects simply
  45.  *                  by returning different class factories here
  46.  *                  for different CLSIDs.
  47.  *
  48.  *  riid            REFIID specifying the interface the caller wants
  49.  *                  on the class object, usually IID_ClassFactory.
  50.  *
  51.  *  ppv             LPVOID FAR* in which to return the interface
  52.  *                  pointer.
  53.  *
  54.  * Returns NOERROR on success, otherwise an error code
  55.  */
  56.  
  57. STDAPI DllGetClassObject(REFCLSID rclsid
  58.     , REFIID riid, LPVOID FAR* ppv) {
  59.   if (!IsEqualCLSID(rclsid, CLSID_SphereCamera))
  60.       return ResultFromScode(E_FAIL);
  61.  
  62.   //Check that we can provide the interface
  63.   if (!IsEqualIID(riid, IID_IUnknown) && !IsEqualIID(riid, IID_IClassFactory))
  64.       return ResultFromScode(E_NOINTERFACE);
  65.  
  66.   //Return our IClassFactory for the correct objects
  67.   if (IsEqualCLSID(rclsid,CLSID_SphereCamera))
  68.       *ppv=(LPVOID) new SphereCameraClassFactory();
  69.  
  70.   if (*ppv == NULL)
  71.       return ResultFromScode(E_OUTOFMEMORY);
  72.  
  73.   //AddRef the object through any interface we return
  74.   ((LPUNKNOWN)*ppv)->AddRef();
  75.  
  76.   return NOERROR;
  77.   }
  78.  
  79.  
  80. /*
  81.  * DllCanUnloadNow
  82.  *
  83.  *  Answers if the DLL can be unload from the memory
  84.  *
  85.  *  This function doesn't need any parameter
  86.  *
  87.  *  Returns TRUE if nothing is using us, FALSE otherwise.
  88.  */
  89.  
  90. STDAPI DllCanUnloadNow() {
  91.   SCODE   sc;
  92.  
  93.   //Our answer is whether there are any object or locks
  94.   sc=(0L==global_count_Obj && 0L==global_count_Lock) ? S_OK : S_FALSE;
  95.   return ResultFromScode(sc);
  96.   }
  97.  
  98. //------------------------------------------------------------------------
  99. //Count number of objects and number of locks.
  100. long       global_count_Obj  = 0;
  101. long       global_count_Lock = 0;
  102.  
  103.